

//把obj对象里的值覆盖到newobj里面
function deepCopy(newobj, obj) {
	if (typeof obj != 'object') {
		return obj
	}
	for (var attr in obj) {
		var a = {}
		if (newobj[attr]) {
			a = newobj[attr]
		}
		newobj[attr] = deepCopy(a, obj[attr])
	}
	return newobj
}

//操作成功后，的提示信息
function successToShow(msg = '保存成功', callback = function() {}) {
	setTimeout(function() {
		uni.showToast({
			title: msg,
			icon: 'success',
			duration: 1000,
			success() {
				setTimeout(function() {
					callback()
				}, 500)
			}
		})
	}, 100)
	/*  uni.showToast({
	    title: msg,
	    icon: 'success',
	    duration: 1000
	  }) */
}

//操作失败的提示信息
function errorToShow(msg = '操作失败', callback = function() {}) {
	setTimeout(function() {
		uni.showToast({
			title: msg,
			icon: 'none',
			duration: 1500,
			success() {
				setTimeout(function() {
					callback()
				}, 1500)
			}
		})
	}, 100)
}




// 提示框
function modelShow({
	title = '提示',
	content = '确认执行此操作吗?',
	callback = () => {},
	showCancel = true,
	cancelText = '取消',
	confirmText = '确定'
}) {
	uni.showModal({
		title: title,
		content: content,
		showCancel: showCancel,
		cancelText: cancelText,
		confirmText: confirmText,
		cancelText: cancelText,
		success: function(res) {
			if (res.confirm) {
				// 用户点击确定操作
				setTimeout(() => {
					callback()
				}, 300)
			} else if (res.cancel) {
				// 用户取消操作
			}
		}
	})
}


/*
 * 保留当前页面，跳转到应用内的某个页面
 */
function navigateTo(url) {
	uni.navigateTo({
		url: url,
		animationType: 'pop-in',
		animationDuration: 300
	})
}
 
/**
 *  关闭当前页面，跳转到应用内的某个页面
 */
function redirectTo(url) {
	uni.redirectTo({
		url: url,
		animationType: 'pop-in',
		animationDuration: 300
	})
}

/**
 *  关闭所有页面，打开到应用内的某个页面
 */
function reLaunch(url) {
	uni.reLaunch({
		url: url,
		animationType: 'pop-in',
		animationDuration: 300
	})
}

/**
 *  跳转到 tabBar 页面，并关闭其他所有非 tabBar 页面
 */
function switchTab(url) {
	uni.switchTab({
		url: url,
		animationType: 'pop-out',
		animationDuration: 300
	})
}

/**
 *  关闭当前页面，返回上一页面或多级页面
 */
function navigateBack(delta) {
	uni.navigateBack({
		delta: delta || 1,
		animationType: 'pop-out',
		animationDuration: 300
	})
}



/**
 * 判断是否为空
 */
function isEmptyTest(value) {
	switch (typeof value) {
		case 'undefined':
			return true;
		case 'string':
			if (value.replace(/(^[ \t\n\r]*)|([ \t\n\r]*$)/g, '').length == 0) return true;
			break;
		case 'boolean':
			if (!value) return true;
			break;
		case 'number':
			if (0 === value || isNaN(value)) return true;
			break;
		case 'object':
			if (null === value || value.length === 0) return true;
			for (var i in value) {
				return false;
			}
			return true;
	}
	return false;
}




export {

	successToShow,

	errorToShow,
	isEmptyTest,



	navigateTo,
	redirectTo,
	reLaunch,
	switchTab,
	navigateBack,
	

}